package controllers

import (

)

func GetEmployees(c *gin.Context)  {
	err, info, total := services.GetAllEmployees()
	if err !=nil{
		app.Error(c,e.ERROR,err,err.Error())
		return
	}
	app.OK(c, map[string]interface{}{"value": info, "total": total},"查询成功")
}

func DelEmployees(c *gin.Context){
	id := -1
	if arg := c.Query("ENumber"); arg != "" {
		id = com.StrTo(arg).MustInt()
	}
	if id == -1{
		app.INFO(c,30001,"参数错误")
		return
	}
	err := services.DelEmployees(id)
	if err !=nil{
		app.Error(c,e.ERROR,err,err.Error())
		return
	}
	app.OK(c, map[string]interface{}{},"删除成功")
}

func UpdateEmployees(c *gin.Context){
	b, _ := c.GetRawData()  //获取原始字节
	var m map[string]string
	_ = json.Unmarshal(b, &m)  //将结构类型转换为json字符串
	if m["ENumber"] == ""{
		app.INFO(c, 30000, "参数非法")
		return
	}
	ENumber := m["EName"]
	EName:=m["EName"]
	Gender:= m["Gender"]
	Birthday:=m["Birthday"]
	HireDate := m["HireDate"]
	DepartmentNumber := m["DepartmentNumber"]
	StaffType := m["StaffType"]
	TechnicalGrade := m["TechnicalGrade"]
	TechnicalTitle := m["TechnicalTitle"]
	EducationDegree := m["EducationDegree"]
	Nation := m["Nation"]
	NativePlace := m["NativePlace"]
	Address := m["Address"]
	err := services.UpdateEmployees(models.Employees{ENumber, EName, Gender,Birthday, HireDate, DepartmentNumber, StaffType, TechnicalTitle, TechnicalGrade, EducationDegree, Nation, NativePlace, Address})

	if err !=nil{
		app.Error(c,e.ERROR,err,err.Error())
		return
	}
	app.OK(c, map[string]interface{}{},"更新成功")
}

func AddEmployees(c *gin.Context){
	b, _ := c.GetRawData()  //获取原始字节
	var m map[string]string
	_ = json.Unmarshal(b, &m)  //将结构类型转换为json字符串
	ENumber := m["ENumber"]
	EName:=m["EName"]
	Gender:= m["Gender"]
	Birthday:=m["Birthday"]
	HireDate := m["HireDate"]
	DepartmentNumber := m["DepartmentNumber"]
	StaffType := m["StaffType"]
	TechnicalGrade := m["TechnicalGrade"]
	TechnicalTitle := m["TechnicalTitle"]
	EducationDegree := m["EducationDegree"]
	Nation := m["Nation"]
	NativePlace := m["NativePlace"]
	Address := m["Address"]
	err := services.AddEmployees(models.Employees{ENumber, EName, Gender,Birthday, HireDate, DepartmentNumber, StaffType, TechnicalTitle, TechnicalGrade, EducationDegree, Nation, NativePlace, Address})

	if err !=nil{
		app.Error(c,e.ERROR,err,err.Error())
		return
	}
	app.OK(c, map[string]interface{}{},"添加成功")
}